package com.example.myapplication22;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.ListView;
import android.widget.SimpleAdapter;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

public class Listview extends AppCompatActivity {
    ListView lv;


    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.list_view);

        lv=(ListView)findViewById(R.id.lv);
        //图片数据
        int[] tu=new int[]{R.drawable.t01,R.drawable.t02,R.drawable.t03, R.drawable.t04,R.drawable.t05 };
        //标题数据
        String[] title = new String[]{"标题1","标题2","标题3","标题4","标题5"};
        //详细信息
        String[] info = new String[]{"详细信息1","详细信息2", "详细信息3","详细信息4","详细信息5"};
        //List中Map
        List<Map<String,Object>> list=new ArrayList<>();
        Map<String,Object> map=new HashMap<>();
        for (int i = 0; i < tu.length; i++) {
            map.put("tu",tu[i]);
            map.put("title",title[i]);
            map.put("info",info[i]);
            list.add(map);
        }
      String[] s=  new String[]{"tu","title","info"};
        //View inflate = View.inflate(this, R.layout.listviewitem, null);

        //控件id数组
        int i[]=new int[]{R.id.image1,R.id.title,R.id.info};
        //System.out.println(list);

       SimpleAdapter simpleAdapter = new SimpleAdapter(this,list,R.layout.listviewitem,s,i);

       lv.setAdapter(simpleAdapter);

    }
}
